<?php
/**
 * Created by JetBrains PhpStorm.
 * User: ZhangYi
 * Date: 11-9-12
 * Time: 下午8:26
 * To change this template use File | Settings | File Templates.
 */

class sfWidgetFormCKFinder extends sfWidgetForm
{

    protected function configure($options = array(), $attributes = array())
    {
        parent::configure($options, $attributes);

    }

    /**
     * Renders the widget.
     *
     * @param  string $name        The element name
     * @param  string $value       The value displayed in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $id = $this->generateId($name);
        $imgId = 'img_' . $id;
        $txtId = 'txt_' . $id;
        $img = $this->renderTag('img', array_merge(array('src' => $value, 'id' => 'img_' . $id), $attributes));
        $input = $this->renderTag('input', array_merge(array('type' => 'text', 'id' => 'txt_' . $id, 'name' => $name, 'value' => $value), $attributes));
        $button = $this->renderTag('input', array_merge(array('type' => 'button', 'value' => '浏览图片', 'name' => $name, 'onclick' => 'getFileUrlFromCKFinder( "' . $txtId . '","' . $imgId . '")')));
        return $img . $input . $button;
    }

}
